package com.example.demo.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.demo.result.RestResponse;
import com.example.demo.result.ResultGenerator;
import com.example.demo.service.UserService;
import com.example.demo.vo.UserVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author wujj
 * @version 1.0
 * @Description: 用户管理
 * @date 2019年04月09日 18:22
 */
@RestController
@RequestMapping("/user")
@Api(value = "UserController", tags = "用户管理")
public class UserController {
    @Autowired
    private UserService userService;


    /**
     * 获取用户列表
     *
     * @param loginName 登录名
     * @param userName  姓名
     * @param idCard    身份证号码
     * @param current   当前页数
     * @param size      每页大小
     * @return
     */
    @GetMapping(value = "/list", produces = "application/json; charset=utf-8")
    @ApiOperation(value = "获取用户列表", notes = "获取用户列表", code = 200, produces = "application/json")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "string", name = "loginName", value = "登录名"),
            @ApiImplicitParam(paramType = "query", dataType = "string", name = "userName", value = "姓名"),
            @ApiImplicitParam(paramType = "query", dataType = "string", name = "idCard", value = "身份证号码"),
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "current", value = "当前页数"),
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "size", value = "每页大小")})
    public RestResponse<IPage<UserVO>> listUser(@RequestParam(name = "loginName", required = false) String loginName,
                                                @RequestParam(name = "userName", required = false) String userName,
                                                @RequestParam(name = "idCard", required = false) String idCard,
                                                @RequestParam(name = "current", defaultValue = "1") Integer current,
                                                @RequestParam(name = "size", defaultValue = "10") Integer size) {

        return ResultGenerator.genSuccessResult(userService.listUser(loginName, userName, idCard, current, size));
    }

}
